package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsClosingDocumentDto;
import com.sale.goods.domain.dto.GoodsCollectionDto;
import com.sale.goods.domain.vo.GoodsCollectionVo;
import com.sale.goods.service.IGoodsCollectionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description 收款单
 * @Date 23-07-19
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/collection")
public class GoodsCollectionController extends BaseController {

    private final IGoodsCollectionService goodsCollectionService;


    /**
     * 获取收款单
     */
    //@SaCheckPermission("finance:collection:list")
    @GetMapping("/list")
    public TableDataInfo<Map<String,String>> list(GoodsCollectionVo goodSCollectionVo, PageQuery pageQuery) {
        return goodsCollectionService.selectCollectionList(goodSCollectionVo, pageQuery);
    }

    /**
     * 获取收款单
     */
    @GetMapping("/ces")
    public TableDataInfo<Map<String, Object>> ces(GoodsCollectionVo goodSCollectionVo, PageQuery pageQuery) {
        return goodsCollectionService.selectCes(goodSCollectionVo, pageQuery);
    }

    /**
     * 新增收款单
     */
    //@SaCheckPermission("finance:collection:add")
    @Log(title = "收款单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsCollectionVo goodsCollectionVo) throws Exception {
        return toAjax(goodsCollectionService.insertCollection(goodsCollectionVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{collectionId}")
    //@SaCheckPermission("finance:collection:query")
    public R getInfo(@PathVariable long collectionId) {
        return R.ok(goodsCollectionService.selectCollectionById(collectionId));
    }

    /**
     * 删除收款单
     */
    //@SaCheckPermission("finance:collection:remove")
    @Log(title = "收款单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{collectionId}")
    public R<Void> remove(@PathVariable("collectionId") Long collectionId) {
        return toAjax(goodsCollectionService.deleteCollectionById(collectionId));
    }

    /**
     * 修改收款单
     */
    //@SaCheckPermission("finance:collection:edit")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsCollectionVo goodsCollectionVo) {
        return toAjax(goodsCollectionService.updateCollectionEdit(goodsCollectionVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:collection:subExamine")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{collectionId}")
    public R<Void> submitReview(@PathVariable("collectionId") Long collectionId) {
        return toAjax(goodsCollectionService.submitReview(collectionId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:collection:revoke")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{collectionId}")
    public R<Void> deleteReview(@PathVariable("collectionId") Long collectionId) {
        return toAjax(goodsCollectionService.deleteReview(collectionId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:collection:examine")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsCollectionVo goodsCollectionVo) throws Exception {
        return toAjax(goodsCollectionService.goodSExamineReview(goodsCollectionVo));
    }

    /**
     * 工作台接口(销售已收款金额)
     */
    @GetMapping("/received")
    public String received() {
        return goodsCollectionService.goodsReceived();
    }

    /**
     * 工作台接口(客户欠款金额)
     */
    @GetMapping("/arrears")
    public String arrears() {
        return goodsCollectionService.goodsArrears();
    }


    /**
     * 结账反结账（财务模块单据查询）
     */
    @GetMapping("/closingCounterClosingDocument")
    public R<GoodsClosingDocumentDto> closingCounterClosingDocument(String time) {
        return R.ok(goodsCollectionService.closingCounterClosingDocument(time));
    }

}
